/* 
 * File:   Clear.cpp
 * Author: saulio
 *
 * Created on April 21, 2013, 1:05 PM
 */


#include "Frame.h"
#include <sys/socket.h>
#include <arpa/inet.h>
#include <sys/msg.h>
#include <stdlib.h>
#include <iostream>
#include <string.h>
#include <unistd.h>
#include <iostream>



/*
 * 
 */
int main() 
{
     
     int unpacker_queue_id_c, unpacker_queue_id_s;
     int log_queue_id;
   
     
     Message_queue inbound_mail;
     Message_queue log_msg;
   
     unpacker_queue_id_c=Message_queue_setup(C_UNPACKER_QUEUE_KEY);
     unpacker_queue_id_s=Message_queue_setup(S_UNPACKER_QUEUE_KEY);
     log_queue_id=Message_queue_setup(LOGGER_QUEUE_KEY);
  
     if(unpacker_queue_id_c==EXIT_FAILURE or  unpacker_queue_id_s==EXIT_FAILURE or log_queue_id==EXIT_FAILURE){
         std::cout<<"Error, el programa ha fallado al crear la cola de mensajes para el (Limpiador),"
                   "verifique si se ha ejecutado con privilegios de root\n";
      
        return(EXIT_FAILURE);
         
     }
     
    
     bzero((char *) &log_msg, sizeof(log_msg));
     log_msg.id_message=LOG_QUEUE_EVNT_CLEAR;
     msgsnd(log_queue_id, (struct msgbuf *)&log_msg,
     sizeof(log_msg)-sizeof(long),IPC_NOWAIT);
     
     bzero((char *) &inbound_mail, sizeof(inbound_mail));
     inbound_mail.id_message=CLRU;
     msgsnd(unpacker_queue_id_c, (struct msgbuf *)&inbound_mail,
     sizeof(inbound_mail.package)+sizeof(inbound_mail.cli_addr),IPC_NOWAIT);

     msgsnd(unpacker_queue_id_s, (struct msgbuf *)&inbound_mail,
     sizeof(inbound_mail.package)+sizeof(inbound_mail.cli_addr),IPC_NOWAIT);
}